package com.lyf.boot.modules.system.controller;

import com.lyf.boot.core.model.IdDto;
import com.lyf.boot.core.model.R;
import com.lyf.boot.modules.system.entity.dto.SysClientDto;
import com.lyf.boot.modules.system.entity.vo.SysClientVo;
import com.lyf.boot.modules.system.service.ISysClientService;
import com.lyf.boot.validate.group.AddGroup;
import com.lyf.boot.validate.group.EditGroup;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 客户端
 * @author Luyufan
 * @date 2024/1/11 10:54
 **/
@RestController
@RequestMapping("sysClient")
@RequiredArgsConstructor
public class SysClientController {

    public final ISysClientService sysClientService;

    /**
     * 获取客户端列表
     * @return
     */
    @PostMapping("getSysClientList")
    public R<List<SysClientVo>> getSysClientList(){
        return R.ok(sysClientService.getSysClientList());
    }

    /**
     * 获取客户端详情
     * @param dto
     * @return
     */
    @PostMapping("getSysClientInfo")
    public R<SysClientVo> getSysClientInfo(@RequestBody @Valid IdDto dto){
        return R.ok(sysClientService.getSysClientById(dto.getId()));
    }

    /**
     * 保存客户端
     * @param dto
     * @return
     */
    @PostMapping("saveSysClient")
    public R<Void> saveSysClient(@RequestBody @Validated(AddGroup.class) SysClientDto dto){
        sysClientService.saveSysClient(dto);
        return R.ok();
    }

    /**
     * 修改客户端
     * @param dto
     * @return
     */
    @PostMapping("updateSysClient")
    public R<Void> updateSysClient(@RequestBody @Validated(EditGroup.class) SysClientDto dto){
        sysClientService.updateSysClient(dto);
        return R.ok();
    }
}
